package cn.stylefeng.guns.modular.fruits.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.fruits.entity.FruitsBasicGoodsInstall;
import cn.stylefeng.guns.modular.fruits.mapper.FruitsBasicGoodsInstallMapper;
import cn.stylefeng.guns.modular.fruits.model.params.FruitsBasicGoodsInstallParam;
import cn.stylefeng.guns.modular.fruits.model.result.FruitsBasicGoodsInstallResult;
import  cn.stylefeng.guns.modular.fruits.service.FruitsBasicGoodsInstallService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * 商品设置 服务实现类
 */
@Service
public class FruitsBasicGoodsInstallServiceImpl extends ServiceImpl<FruitsBasicGoodsInstallMapper, FruitsBasicGoodsInstall> implements FruitsBasicGoodsInstallService {

    @Override
    public void add(FruitsBasicGoodsInstallParam param){
        FruitsBasicGoodsInstall entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(FruitsBasicGoodsInstallParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(FruitsBasicGoodsInstallParam param){
        FruitsBasicGoodsInstall oldEntity = getOldEntity(param);
        FruitsBasicGoodsInstall newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public FruitsBasicGoodsInstallResult findBySpec(FruitsBasicGoodsInstallParam param){
        return this.baseMapper.findBySpec(param);
    }

    @Override
    public List<FruitsBasicGoodsInstallResult> findListBySpec(FruitsBasicGoodsInstallParam param,Long operateId){
        return this.baseMapper.findListBySpec(param,operateId);
    }

    @Override
    public LayuiPageInfo findPageBySpec(FruitsBasicGoodsInstallParam param,String condition){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(FruitsBasicGoodsInstallParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private FruitsBasicGoodsInstall getOldEntity(FruitsBasicGoodsInstallParam param) {
        return this.getById(getKey(param));
    }

    private FruitsBasicGoodsInstall getEntity(FruitsBasicGoodsInstallParam param) {
        FruitsBasicGoodsInstall entity = new FruitsBasicGoodsInstall();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
